package com.tim.android.widget.imageview;

import android.content.Context;
import android.graphics.Canvas;
import android.util.AttributeSet;
import android.view.View;

public class RotatableImageView extends View {
	
	private static final String TAG = "RotatableImageView";
    
    private float mRotateDegree;
    private float mPivotX;
    private float mPivotY;
    
    public RotatableImageView(Context context) {
        super(context);
        mRotateDegree = 0f;
        mPivotX = 0;
        mPivotY = 0;
    }
    
    public RotatableImageView(Context context, AttributeSet attrs) {
		super(context, attrs);
		mRotateDegree = 0f;
		mPivotX = 0;
        mPivotY = 0;
	}
    
    @Override
	protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
		super.onMeasure(widthMeasureSpec, heightMeasureSpec);
		mPivotX = getWidth() / 2;
		mPivotY = getHeight() / 2;
	}

	public void setDegree(float degree) {
        mRotateDegree = degree;
    }
    
    public void setDegree(float degree, float x, float y) {
        mRotateDegree = degree;
        mPivotX = x;
        mPivotY = y;
    }
    
    public float getDegree() {
        return mRotateDegree;
    }
    
    public float getRotateX() {
        return mPivotX;
    }
    
    public float getRotateY() {
        return mPivotY;
    }

    @Override
    public void draw(Canvas canvas) {
    	canvas.save();
    	canvas.rotate(mRotateDegree, mPivotX, mPivotY);
    	super.draw(canvas);
    	canvas.restore();
    }
}
